<!-- 贫困户申请 -->
<template>
    <div class="project-apply">
        <el-card>
            <SelectSearch @getApplyInfo="getPoorApplyInfo" :paginationData="paginationData"></SelectSearch>
            <div class="table">
                <el-table ref="multipleTableRef" :data="tableData" style="width: 100%;" max-height="460px">
                    <el-table-column label="序号" type="index" width="100px" align="center">
                    </el-table-column>
                    <el-table-column prop="username" label="申请用户" width="120px" show-overflow-tooltip />
                    <el-table-column prop="apyExplain" label="申请说明"></el-table-column>
                    <el-table-column prop="createdDt" label="申请时间" width="180px" />
                    <el-table-column prop="apyMaterial" label="申请资料" width="120px">
                        <template #default="scope">
                            <el-button type="warning" size="small" @click="handleDown(scope.row)">下载资料</el-button>
                        </template>
                    </el-table-column>
                    <el-table-column prop="reviewStatus" label="审核状态" width="180px">
                        <template #default="scope">
                            <span v-if="scope.row.reviewStatus == 0">待审核</span>
                            <span v-else-if="scope.row.reviewStatus == 1">审核通过</span>
                            <span v-else-if="scope.row.reviewStatus == 2">审核不通过</span>
                            <span v-else-if="scope.row.reviewStatus == 3">申请已撤销</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="reviewExplain" label="审核说明" width="200px" show-overflow-tooltip />
                    <el-table-column label="操作" align="center" width="100px">
                        <template #default="scope">
                            <el-button size="small" type="primary" v-if="scope.row.reviewStatus == 0"
                                @click="handleChangePoorApplytatus(scope.row)">审
                                核</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="pagination">
                <!-- 分页器 -->
                <Pagination :paginationData="paginationData" @getInfo="getPoorApplyInfo"></Pagination>
            </div>
        </el-card>
        <ApplylDialog @EditApplyInfo="EditApplyInfo" :paginationData="paginationData"></ApplylDialog>
    </div>
</template>

<script setup lang="ts">
import SelectSearch from '../../components/select_search/index.vue'
import Pagination from '../../components/pagination/index.vue'
import ApplylDialog from '../../components/apply_dialog/index.vue'
import { ElMessage } from 'element-plus';
import { onMounted, ref } from 'vue';
import { reqEditPoorApplyInfo, reqGetPoorApplyInfo } from '../../api/apply/poor/index'
import type { AllPoorApply, PoorApplyFormData, PoorApply, EditFromData } from '../../api/apply/poor/type'
import $bus from '../../bus';

// 表格数据
let tableData = ref<AllPoorApply>([])
let key = ref('')
// 存储接口返回的分页器数据
let paginationData = ref({})
onMounted(() => {
    getPoorApplyInfo()

})
//获取全部 订单 信息
const getPoorApplyInfo = async (currentpage = 1, pagesize = 10, keyword = '') => {
    key.value = keyword
    let data: PoorApplyFormData = {
        pageSize: pagesize,
        currentPage: currentpage,
        keyword
    }

    let result: any = await reqGetPoorApplyInfo(data)
    if (result.code == 20000) {
        tableData.value = result.data.list
        paginationData.value = result.data
    }
}



// 下载资料
const handleDown = (row: PoorApply) => {
    console.log(row);

    // const a = document.createElement("a");
    // const event = new MouseEvent("click");
    // a.download = row.attachmentName;
    // a.href = row.apyMaterial;
    // a.dispatchEvent(event)
}

// 审核状态
const handleChangePoorApplytatus = (row: PoorApply) => {
    $bus.emit('showDialog', {
        isShow: true,
        row
    })

}
// 修改审核状态
const EditApplyInfo = async (data: EditFromData) => {
    let result: any = await reqEditPoorApplyInfo(data)
    if (result.code == 20000) {
        // 重新获取 订单 信息
        getPoorApplyInfo(paginationData.value?.currentPage)
        ElMessage({
            type: 'success',
            message: '审核成功'
        })
    } else {
        ElMessage({
            type: 'error',
            message: '审核失败'
        })
    }
}
</script>

<style lang="scss" scoped>
.project-apply {
    .el-form {
        padding: 20px 30px;
    }

    .table {
        margin: 10px 0;

        .el-table {
            font-size: 13px !important;
        }
    }

    .pagination {
        margin-top: 20px;
    }
}
</style>